# -*- coding: utf-8 -*-
# @Time    : 2022/6/28 14:52
# @Author  : zyw
# @Email   : panda_kings@163.com
# @File    : vip.py
import json
from flask import Blueprint,jsonify
from flask_restful import Api,Resource,marshal

from common.models.users import VipModel
from common.model_fields.user_fields import vip_fields

vip_bp = Blueprint('vip',__name__, url_prefix='/vip')

api = Api(vip_bp)


class VIPInfoResource(Resource):
    def get(self):
        """获取VIP信息"""
        vips = VipModel.query.all()
        result = {}
        for vip in vips:
            if vip.level == 0:
                # 是普通用户
                vips = marshal(vips, vip_fields)
                common_list = json.loads(json.dumps(vips))
                # common_list['level']='免费'
                result['common_list']=common_list
            if vip.level == 1:
                common_vip_list = json.loads(json.dumps(marshal(vip, vip_fields)))
                common_vip_list['level'] = '普通会员'
                result['common_vip_list'] = common_vip_list
            if vip.level == 2:
                expert_vip_list = json.loads(json.dumps(marshal(vip, vip_fields)))
                expert_vip_list['level'] = '高级会员'
                result['expert_vip_list'] = expert_vip_list
        return jsonify(message='ok', data=result,code=200)

api.add_resource(VIPInfoResource,'/get_vip_list')